package view;

import java.awt.Font;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import entity.EasyTextArea;

/**
 * 鼠标右键菜单
 * @author Rex
 *
 */
public class RightButtonMenu implements MouseListener{
	
	/**
	 * 右键菜单.
	 */
	private JPopupMenu menu = new JPopupMenu();
	
	/**
	 * 菜单项.
	 */
	private JMenuItem item = new JMenuItem("清空文字");
	
	private EasyTextArea msg;
	
	public RightButtonMenu(EasyTextArea msg, Font font) {
		this.msg = msg;
		item.setFont(font);
		// 将单个菜单项添加到右键菜单列表
		menu.add(item);
		// 为单个菜单项绑定鼠标单击事件
		item.addActionListener(e -> msg.clear()/*清屏*/);
	}

	/**
	 * 监听鼠标点击.
	 */
	@Override
	public void mouseClicked(MouseEvent e) {
		//获取鼠标右键点击的坐标，使右键菜单在用户点击的位置显示
		if(e.getButton() == MouseEvent.BUTTON3){
			menu.show(msg, e.getX(), e.getY());
		}
	}

	@Override
	public void mouseEntered(MouseEvent e) {}
	@Override
	public void mouseExited(MouseEvent e) {}
	@Override
	public void mousePressed(MouseEvent e) {}
	@Override
	public void mouseReleased(MouseEvent e) {}
	
}